<!DOCTYPE html>
<html lang="zh-CN">
    <!-- title -->




<!-- keywords -->




<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" >
    <meta name="author" content="HAOJX">
    <meta name="renderer" content="webkit">
    <meta name="copyright" content="HAOJX">
    
    <meta name="keywords" content="hexo,hexo-theme,docker,kubernetes,Linux,运维">
    
    <meta name="description" content="">
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <title>kuberntes开发教程系列(3)--了解和编写Custom Resources · HAOJX |郝建勋的笔记与博客</title>
    <style type="text/css">
    @font-face {
        font-family: 'Oswald-Regular';
        src: url("/font/Oswald-Regular.ttf");
    }

    body {
        margin: 0;
    }

    header,
    footer,
    .back-top,
    .sidebar,
    .container,
    .site-intro-meta,
    .toc-wrapper {
        display: none;
    }

    .site-intro {
        position: relative;
        z-index: 3;
        width: 100%;
        /* height: 50vh; */
        overflow: hidden;
    }

    .site-intro-placeholder {
        position: absolute;
        z-index: -2;
        top: 0;
        left: 0;
        width: calc(100% + 300px);
        height: 100%;
        background: repeating-linear-gradient(-45deg, #444 0, #444 80px, #333 80px, #333 160px);
        background-position: center center;
        transform: translate3d(-226px, 0, 0);
        animation: gradient-move 2.5s ease-out 0s infinite;
    }

    @keyframes gradient-move {
        0% {
            transform: translate3d(-226px, 0, 0);
        }
        100% {
            transform: translate3d(0, 0, 0);
        }
    }

</style>

    <link rel="preload" href= "/css/style.css?v=20180824" as="style" onload="this.onload=null;this.rel='stylesheet'" />
    <link rel="stylesheet" href= "/css/mobile.css?v=20180824" media="(max-width: 980px)">
    
    <link rel="preload" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.2.5/jquery.fancybox.min.css" as="style" onload="this.onload=null;this.rel='stylesheet'" />
    
    <!-- /*! loadCSS. [c]2017 Filament Group, Inc. MIT License */
/* This file is meant as a standalone workflow for
- testing support for link[rel=preload]
- enabling async CSS loading in browsers that do not support rel=preload
- applying rel preload css once loaded, whether supported or not.
*/ -->
<script>
(function( w ){
	"use strict";
	// rel=preload support test
	if( !w.loadCSS ){
		w.loadCSS = function(){};
	}
	// define on the loadCSS obj
	var rp = loadCSS.relpreload = {};
	// rel=preload feature support test
	// runs once and returns a function for compat purposes
	rp.support = (function(){
		var ret;
		try {
			ret = w.document.createElement( "link" ).relList.supports( "preload" );
		} catch (e) {
			ret = false;
		}
		return function(){
			return ret;
		};
	})();

	// if preload isn't supported, get an asynchronous load by using a non-matching media attribute
	// then change that media back to its intended value on load
	rp.bindMediaToggle = function( link ){
		// remember existing media attr for ultimate state, or default to 'all'
		var finalMedia = link.media || "all";

		function enableStylesheet(){
			link.media = finalMedia;
		}

		// bind load handlers to enable media
		if( link.addEventListener ){
			link.addEventListener( "load", enableStylesheet );
		} else if( link.attachEvent ){
			link.attachEvent( "onload", enableStylesheet );
		}

		// Set rel and non-applicable media type to start an async request
		// note: timeout allows this to happen async to let rendering continue in IE
		setTimeout(function(){
			link.rel = "stylesheet";
			link.media = "only x";
		});
		// also enable media after 3 seconds,
		// which will catch very old browsers (android 2.x, old firefox) that don't support onload on link
		setTimeout( enableStylesheet, 3000 );
	};

	// loop through link elements in DOM
	rp.poly = function(){
		// double check this to prevent external calls from running
		if( rp.support() ){
			return;
		}
		var links = w.document.getElementsByTagName( "link" );
		for( var i = 0; i < links.length; i++ ){
			var link = links[ i ];
			// qualify links to those with rel=preload and as=style attrs
			if( link.rel === "preload" && link.getAttribute( "as" ) === "style" && !link.getAttribute( "data-loadcss" ) ){
				// prevent rerunning on link
				link.setAttribute( "data-loadcss", true );
				// bind listeners to toggle media back
				rp.bindMediaToggle( link );
			}
		}
	};

	// if unsupported, run the polyfill
	if( !rp.support() ){
		// run once at least
		rp.poly();

		// rerun poly on an interval until onload
		var run = w.setInterval( rp.poly, 500 );
		if( w.addEventListener ){
			w.addEventListener( "load", function(){
				rp.poly();
				w.clearInterval( run );
			} );
		} else if( w.attachEvent ){
			w.attachEvent( "onload", function(){
				rp.poly();
				w.clearInterval( run );
			} );
		}
	}


	// commonjs
	if( typeof exports !== "undefined" ){
		exports.loadCSS = loadCSS;
	}
	else {
		w.loadCSS = loadCSS;
	}
}( typeof global !== "undefined" ? global : this ) );
</script>

    <link rel="icon" href= "/assets/favicon.ico" />
    <link rel="preload" href="https://cdn.jsdelivr.net/npm/webfontloader@1.6.28/webfontloader.min.js" as="script" />
    <link rel="preload" href="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js" as="script" />
    <link rel="preload" href="/scripts/main.js" as="script" />
    <link rel="preload" as="font" href="/font/Oswald-Regular.ttf" crossorigin>
    <link rel="preload" as="font" href="https://at.alicdn.com/t/font_327081_1dta1rlogw17zaor.woff" crossorigin>
    
    <!-- fancybox -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.2.5/jquery.fancybox.min.js" defer></script>
    <!-- 百度统计  -->
    
    <!-- 谷歌统计  -->
    
</head>

    
        <body class="post-body">
    
    
<header class="header">

    <div class="read-progress"></div>
    <div class="header-sidebar-menu">&#xe775;</div>
    <!-- post页的toggle banner  -->
    
    <div class="banner">
            <div class="blog-title">
                <a href="/" >HAOJX</a>
            </div>
            <div class="post-title">
                <a href="#" class="post-name">kuberntes开发教程系列(3)--了解和编写Custom Resources</a>
            </div>
    </div>
    
    <a class="home-link" href=/>HAOJX</a>
</header>
    <div class="wrapper">
        <div class="site-intro" style="







height:50vh;
">
    
    <!-- 主页  -->
    
    
    <!-- 404页  -->
            
    <div class="site-intro-placeholder"></div>
    <div class="site-intro-img" style="background-image: url(https://source.unsplash.com/collection/770996/2100x900)"></div>
    <div class="site-intro-meta">
        <!-- 标题  -->
        <h1 class="intro-title">
            <!-- 主页  -->
            
            kuberntes开发教程系列(3)--了解和编写Custom Resources
            <!-- 404 -->
            
        </h1>
        <!-- 副标题 -->
        <p class="intro-subtitle">
            <!-- 主页副标题  -->
            
            
            <!-- 404 -->
            
        </p>
        <!-- 文章页meta -->
        
            <div class="post-intros">
                <!-- 文章页标签  -->
                
                
                    <div class="post-intro-read">
                        <span>字数统计: <span class="post-count word-count">2.7k</span>阅读时长: <span class="post-count reading-time">13 min</span></span>
                    </div>
                
                <div class="post-intro-meta">
                    <span class="post-intro-calander iconfont-archer">&#xe676;</span>
                    <span class="post-intro-time">2019/09/08</span>
                    
                    <span id="busuanzi_container_page_pv" class="busuanzi-pv">
                        <span class="iconfont-archer">&#xe602;</span>
                        <span id="busuanzi_value_page_pv"></span>
                    </span>
                    
                    <span class="shareWrapper">
                        <span class="iconfont-archer shareIcon">&#xe71d;</span>
                        <span class="shareText">Share</span>
                        <ul class="shareList">
                            <li class="iconfont-archer share-qr" data-type="qr">&#xe75b;
                                <div class="share-qrcode"></div>
                            </li>
                            <li class="iconfont-archer" data-type="weibo">&#xe619;</li>
                            <li class="iconfont-archer" data-type="qzone">&#xe62e;</li>
                            <li class="iconfont-archer" data-type="twitter">&#xe634;</li>
                            <li class="iconfont-archer" data-type="facebook">&#xe67a;</li>
                        </ul>
                    </span>
                </div>
            </div>
        
    </div>
</div>
        <script>
 
  // get user agent
  var browser = {
    versions: function () {
      var u = window.navigator.userAgent;
      return {
        userAgent: u,
        trident: u.indexOf('Trident') > -1, //IE内核
        presto: u.indexOf('Presto') > -1, //opera内核
        webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
        gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
        mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
        ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
        android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
        iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者安卓QQ浏览器
        iPad: u.indexOf('iPad') > -1, //是否为iPad
        webApp: u.indexOf('Safari') == -1, //是否为web应用程序，没有头部与底部
        weixin: u.indexOf('MicroMessenger') == -1, //是否为微信浏览器
        uc: u.indexOf('UCBrowser') > -1 //是否为android下的UC浏览器
      };
    }()
  }
  console.log("userAgent:" + browser.versions.userAgent);

  // callback
  function fontLoaded() {
    console.log('font loaded');
    if (document.getElementsByClassName('site-intro-meta')) {
      document.getElementsByClassName('intro-title')[0].classList.add('intro-fade-in');
      document.getElementsByClassName('intro-subtitle')[0].classList.add('intro-fade-in');
      var postIntros = document.getElementsByClassName('post-intros')[0]
      if (postIntros) {
        postIntros.classList.add('post-fade-in');
      }
    }
  }

  // UC不支持跨域，所以直接显示
  function asyncCb(){
    if (browser.versions.uc) {
      console.log("UCBrowser");
      fontLoaded();
    } else {
      WebFont.load({
        custom: {
          families: ['Oswald-Regular']
        },
        loading: function () {  //所有字体开始加载
          // console.log('loading');
        },
        active: function () {  //所有字体已渲染
          fontLoaded();
        },
        inactive: function () { //字体预加载失败，无效字体或浏览器不支持加载
          console.log('inactive: timeout');
          fontLoaded();
        },
        timeout: 5000 // Set the timeout to two seconds
      });
    }
  }

  function asyncErr(){
    console.warn('script load from CDN failed, will load local script')
  }

  // load webfont-loader async, and add callback function
  function async(u, cb, err) {
    var d = document, t = 'script',
      o = d.createElement(t),
      s = d.getElementsByTagName(t)[0];
    o.src = u;
    if (cb) { o.addEventListener('load', function (e) { cb(null, e); }, false); }
    if (err) { o.addEventListener('error', function (e) { err(null, e); }, false); }
    s.parentNode.insertBefore(o, s);
  }

  var asyncLoadWithFallBack = function(arr, success, reject) {
      var currReject = function(){
        reject()
        arr.shift()
        if(arr.length)
          async(arr[0], success, currReject)
        }

      async(arr[0], success, currReject)
  }

  asyncLoadWithFallBack([
    "https://cdn.jsdelivr.net/npm/webfontloader@1.6.28/webfontloader.min.js", 
    "https://cdn.bootcss.com/webfont/1.6.28/webfontloader.js",
    "/lib/webfontloader.min.js"
  ], asyncCb, asyncErr)
</script>        
        <img class="loading" src="/assets/loading.svg" style="display: block; margin: 6rem auto 0 auto; width: 6rem; height: 6rem;" />
        <div class="container container-unloaded">
            <main class="main post-page">
    <article class="article-entry">
        <p>作为kuberntes生态系统中最核心的扩展之一 , Custom Resources(CR) 扮演这重要角色 , 许多成功的项目都离不开CR的使用 ,比如Istio, Linkerd 2.0, AWS App Mesh等等</p>
<p>Kubernetes cluster version 1.7之后, CR作为主要的 Kubernetes API 资源存储在etcd 中 , 如下图所示，如果请求不是以下任何一个请求，则返回到 apiextensions-apiserver，该服务器为通过 CRDs 定义的资源提供服务</p>
<p><img src="https://i.loli.net/2019/09/09/HKfboFOUlg215nJ.png" alt="prku_0401.png"></p>
<ul>
<li>请求如果是aggregation的就使用aggregated API servers处理</li>
<li>如果是原生请求则用Native Kubernetes resources处理</li>
<li>如果是自定义资源 , 则用 apiextensions-apiserver处理</li>
</ul>
<p>一个典型的crd资源如下</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">apiVersion:</span> <span class="string">apiextensions.k8s.io/v1beta1</span></span><br><span class="line"><span class="attr">kind:</span> <span class="string">CustomResourceDefinition</span></span><br><span class="line"><span class="attr">metadata:</span></span><br><span class="line"><span class="attr">  name:</span> <span class="string">ats.cnat.programming-kubernetes.info</span></span><br><span class="line"><span class="attr">spec:</span></span><br><span class="line"><span class="attr">  group:</span> <span class="string">cnat.programming-kubernetes.info</span></span><br><span class="line"><span class="attr">  names:</span></span><br><span class="line"><span class="attr">    kind:</span> <span class="string">At</span></span><br><span class="line"><span class="attr">    listKind:</span> <span class="string">AtList</span></span><br><span class="line"><span class="attr">    plural:</span> <span class="string">ats</span></span><br><span class="line"><span class="attr">    singular:</span> <span class="string">at</span></span><br><span class="line"><span class="attr">  scope:</span> <span class="string">Namespaced</span></span><br><span class="line"><span class="attr">  subresources:</span></span><br><span class="line"><span class="attr">    status:</span> <span class="string">&#123;&#125;</span></span><br><span class="line"><span class="attr">  version:</span> <span class="string">v1alpha1</span></span><br><span class="line"><span class="attr">  versions:</span></span><br><span class="line"><span class="attr">  - name:</span> <span class="string">v1alpha1</span></span><br><span class="line"><span class="attr">    served:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">    storage:</span> <span class="literal">true</span></span><br></pre></td></tr></table></figure>
<h2 id="Discovery-Information"><a href="#Discovery-Information" class="headerlink" title="Discovery Information"></a>Discovery Information</h2><p>kubectl 使用来自 API 服务器的发现信息来发现新资源</p>
<p>我们用kuberntes的verbosity level来看发生了什么</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">$ kubectl get ats -v=7</span><br><span class="line">... GET https://XXX.eks.amazonaws.com/apis/cnat.programming-kubernetes.info/</span><br><span class="line">                                      v1alpha1/namespaces/cnat/ats?<span class="built_in">limit</span>=500</span><br><span class="line">... Request Headers:</span><br><span class="line">... Accept: application/json;as=Table;v=v1beta1;g=meta.k8s.io,application/json</span><br><span class="line">      User-Agent: kubectl/v1.14.0 (darwin/amd64) kubernetes/641856d</span><br><span class="line">... Response Status: 200 OK <span class="keyword">in</span> 607 milliseconds</span><br><span class="line">NAME         AGE</span><br><span class="line">example-at   43s</span><br></pre></td></tr></table></figure>
<ul>
<li>起初 , kubectl并不知道自定义资源的存在</li>
<li>kubectl向API server的/apis的所有已存在的API groups发起请求</li>
<li>接下来，kubectl 通过 / apis / group 版本组发现端点向 API 服务器询问所有现有 API 组中的资源</li>
<li>然后，kubectl 将给定类型 ats 转换为三重类型<ul>
<li>Group ( <code>cnat.programming-kubernetes.info</code>)</li>
<li>Version ( <code>v1alpha1</code>)</li>
<li>Resource (<code>ats</code>)</li>
</ul>
</li>
</ul>
<p>在最后一步中，发现端点提供了进行转化所需的所有信息</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">$ http localhost:8080/apis/</span><br><span class="line">&#123;</span><br><span class="line">  <span class="string">"groups"</span>: [&#123;</span><br><span class="line">    <span class="string">"name"</span>: <span class="string">"at.cnat.programming-kubernetes.info"</span>,</span><br><span class="line">    <span class="string">"preferredVersion"</span>: &#123;</span><br><span class="line">      <span class="string">"groupVersion"</span>: <span class="string">"cnat.programming-kubernetes.info/v1"</span>,</span><br><span class="line">      <span class="string">"version"</span>: <span class="string">"v1alpha1“</span></span><br><span class="line"><span class="string">    &#125;,</span></span><br><span class="line"><span class="string">    "</span>versions<span class="string">": [&#123;</span></span><br><span class="line"><span class="string">      "</span>groupVersion<span class="string">": "</span>cnat.programming-kubernetes.info/v1alpha1<span class="string">",</span></span><br><span class="line"><span class="string">      "</span>version<span class="string">": "</span>v1alpha1<span class="string">"</span></span><br><span class="line"><span class="string">    &#125;]</span></span><br><span class="line"><span class="string">  &#125;, ...]</span></span><br><span class="line"><span class="string">&#125;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">$ http localhost:8080/apis/cnat.programming-kubernetes.info/v1alpha1</span></span><br><span class="line"><span class="string">&#123;</span></span><br><span class="line"><span class="string">  "</span>apiVersion<span class="string">": "</span>v1<span class="string">",</span></span><br><span class="line"><span class="string">  "</span>groupVersion<span class="string">": "</span>cnat.programming-kubernetes.info/v1alpha1<span class="string">",</span></span><br><span class="line"><span class="string">  "</span>kind<span class="string">": "</span>APIResourceList<span class="string">",</span></span><br><span class="line"><span class="string">  "</span>resources<span class="string">": [&#123;</span></span><br><span class="line"><span class="string">    "</span>kind<span class="string">": "</span>At<span class="string">",</span></span><br><span class="line"><span class="string">    "</span>name<span class="string">": "</span>ats<span class="string">",</span></span><br><span class="line"><span class="string">    "</span>namespaced<span class="string">": true,</span></span><br><span class="line"><span class="string">    "</span>verbs<span class="string">": ["</span>create<span class="string">", "</span>delete<span class="string">", "</span>deletecollection<span class="string">",</span></span><br><span class="line"><span class="string">      "</span>get<span class="string">", "</span>list<span class="string">", "</span>patch<span class="string">", "</span>update<span class="string">", "</span>watch<span class="string">"</span></span><br><span class="line"><span class="string">    ]</span></span><br><span class="line"><span class="string">  &#125;, ...]</span></span><br><span class="line"><span class="string">&#125;</span></span><br></pre></td></tr></table></figure>
<p>这些都是通过发现 RESTMapper 实现的</p>
<blockquote>
<p>kubectl会在  ~/.kubectl目录下把自己发现的所有资源类型缓存下来 , 每过10分钟失效一次,重新 开始开始发现, 所有我们自定义的资源会在10分钟后出现在此缓存中</p>
</blockquote>
<h2 id="自定义资源的编写"><a href="#自定义资源的编写" class="headerlink" title="自定义资源的编写"></a>自定义资源的编写</h2><p>自定义资源就是CRD 格式如下:</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">apiVersion:</span> <span class="string">apiextensions.k8s.io/v1beta1</span></span><br><span class="line"><span class="attr">kind:</span> <span class="string">CustomResourceDefinition</span></span><br><span class="line"><span class="attr">metadata:</span></span><br><span class="line"><span class="attr">  name:</span> <span class="string">name</span></span><br><span class="line"><span class="attr">spec:</span></span><br><span class="line"><span class="attr">  group:</span> <span class="string">group</span> <span class="string">name</span></span><br><span class="line"><span class="attr">  version:</span> <span class="string">version</span> <span class="string">name</span></span><br><span class="line"><span class="attr">  names:</span></span><br><span class="line"><span class="attr">    kind:</span> <span class="string">uppercase</span> <span class="string">name</span></span><br><span class="line"><span class="attr">    plural:</span> <span class="string">lowercase</span> <span class="string">plural</span> <span class="string">name</span></span><br><span class="line"><span class="attr">    singular:</span> <span class="string">lowercase</span> <span class="string">singular</span> <span class="string">name</span> <span class="comment"># defaulted to be lowercase kind</span></span><br><span class="line"><span class="attr">    shortNames:</span> <span class="string">list</span> <span class="string">of</span> <span class="string">strings</span> <span class="string">as</span> <span class="string">short</span> <span class="string">names</span> <span class="comment"># optional</span></span><br><span class="line"><span class="attr">    listKind:</span> <span class="string">uppercase</span> <span class="string">list</span> <span class="string">kind</span> <span class="comment"># defaulted to be kindList</span></span><br><span class="line"><span class="attr">    categories:</span> <span class="string">list</span> <span class="string">of</span> <span class="string">category</span> <span class="string">membership</span> <span class="string">like</span> <span class="string">"all"</span> <span class="comment"># optional</span></span><br><span class="line"><span class="attr">  validation:</span> <span class="comment"># optional</span></span><br><span class="line"><span class="attr">    openAPIV3Schema:</span> <span class="string">OpenAPI</span> <span class="string">schema</span> <span class="comment"># optional</span></span><br><span class="line"><span class="attr">  subresources:</span> <span class="comment"># optional</span></span><br><span class="line"><span class="attr">    status:</span> <span class="string">&#123;&#125;</span> <span class="comment"># to enable the status subresource (optional)</span></span><br><span class="line"><span class="attr">    scale:</span> <span class="comment"># optional</span></span><br><span class="line"><span class="attr">      specReplicasPath:</span> <span class="string">JSON</span> <span class="string">path</span> <span class="string">for</span> <span class="string">the</span> <span class="string">replica</span> <span class="string">number</span> <span class="string">in</span> <span class="string">the</span> <span class="string">spec</span> <span class="string">of</span> <span class="string">the</span></span><br><span class="line">                        <span class="string">custom</span> <span class="string">resource</span></span><br><span class="line"><span class="attr">      statusReplicasPath:</span> <span class="string">JSON</span> <span class="string">path</span> <span class="string">for</span> <span class="string">the</span> <span class="string">replica</span> <span class="string">number</span> <span class="string">in</span> <span class="string">the</span> <span class="string">status</span> <span class="string">of</span></span><br><span class="line">                          <span class="string">the</span> <span class="string">custom</span> <span class="string">resource</span></span><br><span class="line"><span class="attr">      labelSelectorPath:</span> <span class="string">JSON</span> <span class="string">path</span> <span class="string">of</span> <span class="string">the</span> <span class="string">Scale.Status.Selector</span> <span class="string">field</span> <span class="string">in</span> <span class="string">the</span></span><br><span class="line">                         <span class="string">scale</span> <span class="string">resource</span></span><br><span class="line"><span class="attr">  versions:</span> <span class="comment"># defaulted to the Spec.Version field</span></span><br><span class="line"><span class="attr">  - name:</span> <span class="string">version</span> <span class="string">name</span></span><br><span class="line"><span class="attr">    served:</span> <span class="string">boolean</span> <span class="string">whether</span> <span class="string">the</span> <span class="string">version</span> <span class="string">is</span> <span class="string">served</span> <span class="string">by</span> <span class="string">the</span> <span class="string">API</span> <span class="string">server</span> <span class="comment"># defaults to false</span></span><br><span class="line"><span class="attr">    storage:</span> <span class="string">boolean</span> <span class="string">whether</span> <span class="string">this</span> <span class="string">version</span> <span class="string">is</span> <span class="string">the</span> <span class="string">version</span> <span class="string">used</span> <span class="string">to</span> <span class="string">store</span> <span class="string">object</span></span><br><span class="line"><span class="bullet">  -</span> <span class="string">...</span></span><br></pre></td></tr></table></figure>
<p>定义之后提交, API server就开始可以进行验证了, API server验证这些字段是采用<span style="color:red">OpenAPI v3 schema</span> 模式完成的, OpenAPI schema是基于<a href="https://tools.ietf.org/html/draft-wright-json-schema-validation-00" target="_blank" rel="noopener">JSON Schema standard</a> , 使用JSON/YAML来表达一个schema , 下面是个例子</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">type:</span> <span class="string">object</span></span><br><span class="line"><span class="attr">properties:</span></span><br><span class="line"><span class="attr">  apiVersion:</span></span><br><span class="line"><span class="attr">    type:</span> <span class="string">string</span></span><br><span class="line"><span class="attr">  kind:</span></span><br><span class="line"><span class="attr">    type:</span> <span class="string">string</span></span><br><span class="line"><span class="attr">  metadata:</span></span><br><span class="line"><span class="attr">    type:</span> <span class="string">object</span></span><br><span class="line"><span class="attr">  spec:</span></span><br><span class="line"><span class="attr">    type:</span> <span class="string">object</span></span><br><span class="line"><span class="attr">    properties:</span></span><br><span class="line"><span class="attr">      schedule:</span></span><br><span class="line"><span class="attr">        type:</span> <span class="string">string</span></span><br><span class="line"><span class="attr">        pattern:</span> <span class="string">"^\d&#123;4&#125;-([0]\d|1[0-2])-([0-2]\d|3[01])..."</span></span><br><span class="line"><span class="attr">      command:</span></span><br><span class="line"><span class="attr">        type:</span> <span class="string">string</span></span><br><span class="line"><span class="attr">    required:</span></span><br><span class="line"><span class="bullet">    -</span> <span class="string">schedule</span></span><br><span class="line"><span class="bullet">    -</span> <span class="string">command</span></span><br><span class="line"><span class="attr">  status:</span></span><br><span class="line"><span class="attr">    type:</span> <span class="string">object</span></span><br><span class="line"><span class="attr">    properties:</span></span><br><span class="line"><span class="attr">      phase:</span></span><br><span class="line"><span class="attr">        type:</span> <span class="string">string</span></span><br><span class="line"><span class="attr">required:</span></span><br><span class="line"><span class="bullet">-</span> <span class="string">metadata</span></span><br><span class="line"><span class="bullet">-</span> <span class="string">apiVersion</span></span><br><span class="line"><span class="bullet">-</span> <span class="string">kind</span></span><br><span class="line"><span class="bullet">-</span> <span class="string">spec</span></span><br></pre></td></tr></table></figure>
<p>上述schema其实是个JSON object , 每个JSON object中的spec 必须要求有2个字段:<code>schedule</code> and <code>command</code> , schedule匹配一个ISO date(这里是用正则表达式匹配)</p>
<h3 id="Short-Names-and-Categories"><a href="#Short-Names-and-Categories" class="headerlink" title="Short Names and Categories"></a>Short Names and Categories</h3><p>和本地资源一样, 自定义资源也可以用自己的短名称 , 比如namespace的简称就是ns , 我们可以用<code>kubectl get ns</code>来获取 </p>
<p>查看所有可用的短名称 , 我们可以使用以下命令</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">$ kubectl api-resources</span><br><span class="line">NAME                   SHORTNAMES  APIGROUP NAMESPACED  KIND</span><br><span class="line">bindings                                    <span class="literal">true</span>        Binding</span><br><span class="line">componentstatuses      cs                   <span class="literal">false</span>       ComponentStatus</span><br><span class="line">configmaps             cm                   <span class="literal">true</span>        ConfigMap</span><br><span class="line">endpoints              ep                   <span class="literal">true</span>        Endpoints</span><br><span class="line">events                 ev                   <span class="literal">true</span>        Event</span><br><span class="line">limitranges            limits               <span class="literal">true</span>        LimitRange</span><br><span class="line">namespaces             ns                   <span class="literal">false</span>       Namespace</span><br><span class="line">nodes                  no                   <span class="literal">false</span>       Node</span><br><span class="line">persistentvolumeclaims pvc                  <span class="literal">true</span>       PersistentVolumeClaim</span><br><span class="line">persistentvolumes      pv                   <span class="literal">false</span>       PersistentVolume</span><br><span class="line">pods                   po                   <span class="literal">true</span>        Pod</span><br><span class="line">statefulsets           sts         apps     <span class="literal">true</span>        StatefulSet</span><br><span class="line">...</span><br></pre></td></tr></table></figure>
<p>如何自定义短名称呢</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">apiVersion:</span> <span class="string">apiextensions.k8s.io/v1beta1</span></span><br><span class="line"><span class="attr">kind:</span> <span class="string">CustomResourceDefinition</span></span><br><span class="line"><span class="attr">metadata:</span></span><br><span class="line"><span class="attr">  name:</span> <span class="string">ats.cnat.programming-kubernetes.info</span></span><br><span class="line"><span class="attr">spec:</span></span><br><span class="line">  <span class="string">...</span></span><br><span class="line"><span class="attr">  shortNames:</span></span><br><span class="line"><span class="bullet">  -</span> <span class="string">at</span></span><br></pre></td></tr></table></figure>
<p>当然还可以把他们加入一个categories</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">apiVersion:</span> <span class="string">apiextensions.k8s.io/v1beta1</span></span><br><span class="line"><span class="attr">kind:</span> <span class="string">CustomResourceDefinition</span></span><br><span class="line"><span class="attr">metadata:</span></span><br><span class="line"><span class="attr">  name:</span> <span class="string">ats.cnat.programming-kubernetes.info</span></span><br><span class="line"><span class="attr">spec:</span></span><br><span class="line">  <span class="string">...</span></span><br><span class="line"><span class="attr">  categories:</span></span><br><span class="line"><span class="bullet">  -</span> <span class="string">all</span></span><br></pre></td></tr></table></figure>
<h3 id="Printer-Columns"><a href="#Printer-Columns" class="headerlink" title="Printer Columns"></a>Printer Columns</h3><p>Kubectl CLI 工具使用服务器端打印来呈现 kubectl get 的输出。 这意味着它会向 API 服务器查询要显示的列和每一行中的值</p>
<p>通过 additionalPrinterColumns，自定义资源也支持服务器端打印列,它们被称为“ additional”</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">apiVersion:</span> <span class="string">apiextensions.k8s.io/v1beta1</span></span><br><span class="line"><span class="attr">kind:</span> <span class="string">CustomResourceDefinition</span></span><br><span class="line"><span class="attr">metadata:</span></span><br><span class="line"><span class="attr">  name:</span> <span class="string">ats.cnat.programming-kubernetes.info</span></span><br><span class="line"><span class="attr">spec:</span></span><br><span class="line"><span class="attr">  additionalPrinterColumns:</span> <span class="string">(optional)</span></span><br><span class="line"><span class="attr">  - name:</span> <span class="string">kubectl</span> <span class="string">column</span> <span class="string">name</span></span><br><span class="line"><span class="attr">    type:</span> <span class="string">OpenAPI</span> <span class="string">type</span> <span class="string">for</span> <span class="string">the</span> <span class="string">column</span></span><br><span class="line"><span class="attr">    format:</span> <span class="string">OpenAPI</span> <span class="string">format</span> <span class="string">for</span> <span class="string">the</span> <span class="string">column</span> <span class="string">(optional)</span></span><br><span class="line"><span class="attr">    description:</span> <span class="string">human-readable</span> <span class="string">description</span> <span class="string">of</span> <span class="string">the</span> <span class="string">column</span> <span class="string">(optional)</span></span><br><span class="line"><span class="attr">    priority:</span> <span class="string">integer,</span> <span class="string">always</span> <span class="string">zero</span> <span class="string">supported</span> <span class="string">by</span> <span class="string">kubectl</span></span><br><span class="line"><span class="attr">    JSONPath:</span> <span class="string">JSON</span> <span class="string">path</span> <span class="string">inside</span> <span class="string">the</span> <span class="string">CR</span> <span class="string">for</span> <span class="string">the</span> <span class="string">displayed</span> <span class="string">value</span></span><br></pre></td></tr></table></figure>
<p>比如我们在自定义资源中添加如下字段</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">additionalPrinterColumns:</span> <span class="comment">#(optional)</span></span><br><span class="line"><span class="attr">- name:</span> <span class="string">schedule</span></span><br><span class="line"><span class="attr">  type:</span> <span class="string">string</span></span><br><span class="line"><span class="attr">  JSONPath:</span> <span class="string">.spec.schedule</span></span><br><span class="line"><span class="attr">- name:</span> <span class="string">command</span></span><br><span class="line"><span class="attr">  type:</span> <span class="string">string</span></span><br><span class="line"><span class="attr">  JSONPath:</span> <span class="string">.spec.command</span></span><br><span class="line"><span class="attr">- name:</span> <span class="string">phase</span></span><br><span class="line"><span class="attr">  type:</span> <span class="string">string</span></span><br><span class="line"><span class="attr">  JSONPath:</span> <span class="string">.status.phase</span></span><br></pre></td></tr></table></figure>
<p>之后我们使用kubectl来获取</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ kubectl get ats</span><br><span class="line">NAME  SCHEDULER             COMMAND             PHASE</span><br><span class="line">foo   2019-07-03T02:00:00Z  <span class="built_in">echo</span> <span class="string">"hello world"</span>  Pending</span><br></pre></td></tr></table></figure>
<h2 id="子资源状态"><a href="#子资源状态" class="headerlink" title="子资源状态"></a>子资源状态</h2><h3 id="status状态子资源启用"><a href="#status状态子资源启用" class="headerlink" title="status状态子资源启用"></a>status状态子资源启用</h3><p>例子:</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">apiVersion:</span> <span class="string">apiextensions.k8s.io/v1beta1</span></span><br><span class="line"><span class="attr">kind:</span> <span class="string">CustomResourceDefinition</span></span><br><span class="line"><span class="attr">spec:</span></span><br><span class="line">  <span class="string">...</span></span><br><span class="line"><span class="attr">  versions:</span></span><br><span class="line"><span class="attr">  - name:</span> <span class="string">v1alpha1</span></span><br><span class="line"><span class="attr">    served:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">    storage:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">  - name:</span> <span class="string">v1beta1</span></span><br><span class="line"><span class="attr">    served:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">    subresources:</span></span><br><span class="line"><span class="attr">      status:</span> <span class="string">&#123;&#125;</span></span><br></pre></td></tr></table></figure>
<p>其中status中的字段要为空, 这是因为这些字段的填写是系统填写的</p>
<h3 id="scale子资源"><a href="#scale子资源" class="headerlink" title="scale子资源"></a>scale子资源</h3><p>它允许我们查看和修改副本值</p>
<p>比如我们想用kubectl scale来扩展副本数量</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ kubectl scale --replicas=3 your-custom-resource -v=7</span><br><span class="line">I0429 21:17:53.138353   66743 round_trippers.go:383] PUT</span><br><span class="line">https://host/apis/group/v1/your-custom-resource/scale</span><br></pre></td></tr></table></figure>
<p>在进行自定义资源定义的时候 , 我们可以</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">apiVersion:</span> <span class="string">apiextensions.k8s.io/v1beta1</span></span><br><span class="line"><span class="attr">kind:</span> <span class="string">CustomResourceDefinition</span></span><br><span class="line"><span class="attr">spec:</span></span><br><span class="line"><span class="attr">  subresources:</span></span><br><span class="line"><span class="attr">    scale:</span></span><br><span class="line"><span class="attr">      specReplicasPath:</span> <span class="string">.spec.replicas</span></span><br><span class="line"><span class="attr">      statusReplicasPath:</span> <span class="string">.status.replicas</span></span><br><span class="line"><span class="attr">      labelSelectorPath:</span> <span class="string">.status.labelSelector</span></span><br><span class="line">  <span class="string">...</span></span><br></pre></td></tr></table></figure>
<p>这样replica的值就由从GET返回的值填充到spec.replicas中去了</p>
<h2 id="使用golang访问Custom-resources"><a href="#使用golang访问Custom-resources" class="headerlink" title="使用golang访问Custom resources"></a>使用golang访问Custom resources</h2><p>我们可以使用多种client来访问Custom resources</p>
<ul>
<li><p>使用dynamic client</p>
</li>
<li><p>使用typed client</p>
<p>目前有2种方式生成类型化客户端</p>
<ul>
<li>一种是由框架生成, 比如typed client和Kubebuilder提供的<a href="https://github.com/kubernetes-sigs/controller-runtime" target="_blank" rel="noopener">kubernetes-sigs/controller-runtime</a>来生成</li>
<li>第二种方法是由<a href="https://github.com/kubernetes/client-go/tree/ee7a1ba5cdf1292b67a1fdf1fa28f90d2a7b0084/kubernetes" target="_blank" rel="noopener"><em>k8s.io/client-go/kubernetes</em></a>提供的client-gen生成</li>
</ul>
</li>
</ul>
<h3 id="Dynamic-Client"><a href="#Dynamic-Client" class="headerlink" title="Dynamic Client"></a>Dynamic Client</h3><p>Dynamic Client不使用RESTMapper , 得手动添加类型</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">schema.GroupVersionResource&#123;</span></span><br><span class="line"><span class="attr">  Group:</span> <span class="string">"apps"</span><span class="string">,</span></span><br><span class="line"><span class="attr">  Version:</span> <span class="string">"v1"</span><span class="string">,</span></span><br><span class="line"><span class="attr">  Resource:</span> <span class="string">"deployments"</span><span class="string">,</span></span><br><span class="line"><span class="string">&#125;</span></span><br></pre></td></tr></table></figure>
<p>如果 REST 客户端配置可用 ，动态客户端可以在一行中创建</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">client, err := NewForConfig(cfg)</span><br></pre></td></tr></table></figure>
<p>对给定的 GVR 的 REST 访问同样简单</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">client.Resource(gvr).</span><br><span class="line">   Namespace(namespace).Get(<span class="string">"foo"</span>, metav1.GetOptions&#123;&#125;)</span><br></pre></td></tr></table></figure>
<h3 id="Typed-Clients"><a href="#Typed-Clients" class="headerlink" title="Typed Clients"></a>Typed Clients</h3><p>常见的一个做法是把它放进一个约定的包里</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pkg/apis/group/version</span><br></pre></td></tr></table></figure>
<p>然后在<em>types.go</em>里面定义类型</p>
<p>每一个与 GVK 相对应的 Golang 类型都嵌入了来自包装 k8s.io/apimachinery/pkg/apis/meta/v1的 TypeMeta 结构。 只包含 Kind 和 ApiVersion 字段</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">type</span> <span class="string">TypeMeta</span> <span class="string">struct</span> <span class="string">&#123;</span></span><br><span class="line">    <span class="string">//</span> <span class="string">+optional</span></span><br><span class="line">    <span class="string">APIVersion</span> <span class="string">string</span> <span class="string">`json:"apiVersion,omitempty"</span> <span class="attr">yaml:"apiVersion,omitempty"`</span></span><br><span class="line">    <span class="string">//</span> <span class="string">+optional</span></span><br><span class="line">    <span class="string">Kind</span> <span class="string">string</span> <span class="string">`json:"kind,omitempty"</span> <span class="attr">yaml:"kind,omitempty"`</span></span><br><span class="line"><span class="string">&#125;</span></span><br></pre></td></tr></table></figure>
<p>此外还需要一个名称以及名称空间等等字段, 他们存储在一个名为 ObjectMeta 的结构体中，该结构体位在k8s.io/apimachinery/pkg/apis/meta/v1文件包中</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> ObjectMeta <span class="keyword">struct</span> &#123;</span><br><span class="line">    Name <span class="keyword">string</span> <span class="string">`json:"name,omitempty"`</span></span><br><span class="line">    Namespace <span class="keyword">string</span> <span class="string">`json:"namespace,omitempty"`</span></span><br><span class="line">    UID types.UID <span class="string">`json:"uid,omitempty"`</span></span><br><span class="line">    ResourceVersion <span class="keyword">string</span> <span class="string">`json:"resourceVersion,omitempty"`</span></span><br><span class="line">    CreationTimestamp Time <span class="string">`json:"creationTimestamp,omitempty"`</span></span><br><span class="line">    DeletionTimestamp *Time <span class="string">`json:"deletionTimestamp,omitempty"`</span></span><br><span class="line">    Labels <span class="keyword">map</span>[<span class="keyword">string</span>]<span class="keyword">string</span> <span class="string">`json:"labels,omitempty"`</span></span><br><span class="line">    Annotations <span class="keyword">map</span>[<span class="keyword">string</span>]<span class="keyword">string</span> <span class="string">`json:"annotations,omitempty"`</span></span><br><span class="line">    ...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>Kubernetes 顶级类型(即那些具有嵌入式 TypeMeta 和嵌入式 ObjectMeta 的类型，并且在本例中被持久化到 etcd 中)看起来非常相似，因为它们通常具有 spec 和status。 看看这个来自 k8s.io/kubernetes/apps/v1/types.go 的部署示例</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> Deployment <span class="keyword">struct</span> &#123;</span><br><span class="line">    metav1.TypeMeta <span class="string">`json:",inline"`</span></span><br><span class="line">    metav1.ObjectMeta <span class="string">`json:"metadata,omitempty"`</span></span><br><span class="line"></span><br><span class="line">    Spec DeploymentSpec <span class="string">`json:"spec,omitempty"`</span></span><br><span class="line">    Status DeploymentStatus <span class="string">`json:"status,omitempty"`</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="golang包的组织"><a href="#golang包的组织" class="headerlink" title="golang包的组织"></a>golang包的组织</h2><p>Golang 类型通常放在一个名为 types.go 的文件中,放在包<em>pkg/apis/group/version</em> 中 , 除了这个文件还有其他文件</p>
<p>doc.go文件描述了 API 的用途，并包含了一些 package-global 代码生成标签</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// Package v1alpha1 contains the cnat v1alpha1 API group</span></span><br><span class="line"><span class="comment">//</span></span><br><span class="line"><span class="comment">// +k8s:deepcopy-gen=package</span></span><br><span class="line"><span class="comment">// +groupName=cnat.programming-kubernetes.info</span></span><br><span class="line"><span class="keyword">package</span> v1alpha1</span><br></pre></td></tr></table></figure>
<p>register.go 文件将custom resource Golang types注册到scheme中</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> version</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">    metav1 <span class="string">"k8s.io/apimachinery/pkg/apis/meta/v1"</span></span><br><span class="line">    <span class="string">"k8s.io/apimachinery/pkg/runtime"</span></span><br><span class="line">    <span class="string">"k8s.io/apimachinery/pkg/runtime/schema"</span></span><br><span class="line"></span><br><span class="line">    group <span class="string">"repo/pkg/apis/group"</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="comment">// SchemeGroupVersion is group version used to register these objects</span></span><br><span class="line"><span class="keyword">var</span> SchemeGroupVersion = schema.GroupVersion&#123;</span><br><span class="line">    Group: group.GroupName,</span><br><span class="line">    Version: <span class="string">"version"</span>,</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// Kind takes an unqualified kind and returns back a Group qualified GroupKind</span></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">Kind</span><span class="params">(kind <span class="keyword">string</span>)</span> <span class="title">schema</span>.<span class="title">GroupKind</span></span> &#123;</span><br><span class="line">    <span class="keyword">return</span> SchemeGroupVersion.WithKind(kind).GroupKind()</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// Resource takes an unqualified resource and returns a Group</span></span><br><span class="line"><span class="comment">// qualified GroupResource</span></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">Resource</span><span class="params">(resource <span class="keyword">string</span>)</span> <span class="title">schema</span>.<span class="title">GroupResource</span></span> &#123;</span><br><span class="line">    <span class="keyword">return</span> SchemeGroupVersion.WithResource(resource).GroupResource()</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> (</span><br><span class="line">    SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)</span><br><span class="line">    AddToScheme   = SchemeBuilder.AddToScheme</span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="comment">// Adds the list of known types to Scheme.</span></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">addKnownTypes</span><span class="params">(scheme *runtime.Scheme)</span> <span class="title">error</span></span> &#123;</span><br><span class="line">    scheme.AddKnownTypes(SchemeGroupVersion,</span><br><span class="line">        &amp;SomeKind&#123;&#125;,</span><br><span class="line">        &amp;SomeKindList&#123;&#125;,</span><br><span class="line">    )</span><br><span class="line">    metav1.AddToGroupVersion(scheme, SchemeGroupVersion)</span><br><span class="line">    <span class="keyword">return</span> <span class="literal">nil</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>之后<em>zz_generated.deepcopy.go</em>文件自动生成 , 它定义了custom resource Golang top-level types的deep-copy method , 关于如何用go的注释标签自动生成代码, 我们下一讲再说</p>
<h3 id="通过client-gen生成typed-client"><a href="#通过client-gen生成typed-client" class="headerlink" title="通过client-gen生成typed client"></a>通过client-gen生成typed client</h3><p>在<em>pkg/apis/group/version</em>这个地方 , client generator <code>client-gen</code>在<em>pkg/generated/clientset/versioned</em> (老版本是/client/clientset/versioned里面生成)生成了一个typed client</p>
<p>它长的是这样</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// Code generated by client-gen. DO NOT EDIT.</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">package</span> versioned</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">    discovery <span class="string">"k8s.io/client-go/discovery"</span></span><br><span class="line">    rest <span class="string">"k8s.io/client-go/rest"</span></span><br><span class="line">    flowcontrol <span class="string">"k8s.io/client-go/util/flowcontrol"</span></span><br><span class="line"></span><br><span class="line">    cnatv1alpha1 <span class="string">".../cnat/cnat-client-go/pkg/generated/clientset/versioned/</span></span><br><span class="line"><span class="string">)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">type Interface interface &#123;</span></span><br><span class="line"><span class="string">    Discovery() discovery.DiscoveryInterface</span></span><br><span class="line"><span class="string">    CnatV1alpha1() cnatv1alpha1.CnatV1alpha1Interface</span></span><br><span class="line"><span class="string">&#125;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">// Clientset contains the clients for groups. Each group has exactly one</span></span><br><span class="line"><span class="string">// version included in a Clientset.</span></span><br><span class="line"><span class="string">type Clientset struct &#123;</span></span><br><span class="line"><span class="string">    *discovery.DiscoveryClient</span></span><br><span class="line"><span class="string">    cnatV1alpha1 *cnatv1alpha1.CnatV1alpha1Client</span></span><br><span class="line"><span class="string">&#125;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">// CnatV1alpha1 retrieves the CnatV1alpha1Client</span></span><br><span class="line"><span class="string">func (c *Clientset) CnatV1alpha1() cnatv1alpha1.CnatV1alpha1Interface &#123;</span></span><br><span class="line"><span class="string">    return c.cnatV1alpha1</span></span><br><span class="line"><span class="string">&#125;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">// Discovery retrieves the DiscoveryClient</span></span><br><span class="line"><span class="string">func (c *Clientset) Discovery() discovery.DiscoveryInterface &#123;</span></span><br><span class="line"><span class="string">   ...</span></span><br><span class="line"><span class="string">&#125;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">// NewForConfig creates a new Clientset for the given config.</span></span><br><span class="line"><span class="string">func NewForConfig(c *rest.Config) (*Clientset, error) &#123;</span></span><br><span class="line"><span class="string">    ...</span></span><br><span class="line"><span class="string">&#125;</span></span><br></pre></td></tr></table></figure>
<p>这个clinet set由interface <code>Interface</code> 表示,并为每个版本提供对 API 组客户端接口的访问接口ー例如，下面的示例代码中的 cnatv1alpha1接口:</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">type</span> CnatV1alpha1Interface <span class="keyword">interface</span> &#123;</span><br><span class="line">    RESTClient() rest.Interface</span><br><span class="line">    AtsGetter</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// AtsGetter has a method to return a AtInterface.</span></span><br><span class="line"><span class="comment">// A group's client should implement this interface.</span></span><br><span class="line"><span class="keyword">type</span> AtsGetter <span class="keyword">interface</span> &#123;</span><br><span class="line">    Ats(namespace <span class="keyword">string</span>) AtInterface</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// AtInterface has methods to work with At resources.</span></span><br><span class="line"><span class="keyword">type</span> AtInterface <span class="keyword">interface</span> &#123;</span><br><span class="line">    Create(*v1alpha1.At) (*v1alpha1.At, error)</span><br><span class="line">    Update(*v1alpha1.At) (*v1alpha1.At, error)</span><br><span class="line">    UpdateStatus(*v1alpha1.At) (*v1alpha1.At, error)</span><br><span class="line">    Delete(name <span class="keyword">string</span>, options *v1.DeleteOptions) error</span><br><span class="line">    DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error</span><br><span class="line">    Get(name <span class="keyword">string</span>, options v1.GetOptions) (*v1alpha1.At, error)</span><br><span class="line">    List(opts v1.ListOptions) (*v1alpha1.AtList, error)</span><br><span class="line">    Watch(opts v1.ListOptions) (watch.Interface, error)</span><br><span class="line">    Patch(name <span class="keyword">string</span>, pt types.PatchType, data []<span class="keyword">byte</span>, subresources ...<span class="keyword">string</span>)</span><br><span class="line">        (result *v1alpha1.At, err error)</span><br><span class="line">    AtExpansion</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>可以使用 NewForConfig 函数创建client set的实例</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> (</span><br><span class="line">    metav1 <span class="string">"k8s.io/apimachinery/pkg/apis/meta/v1"</span></span><br><span class="line">    <span class="string">"k8s.io/client-go/tools/clientcmd"</span></span><br><span class="line"></span><br><span class="line">    client <span class="string">"github.com/.../cnat/cnat-client-go/pkg/generated/clientset/versioned"</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line">kubeconfig = flag.String(<span class="string">"kubeconfig"</span>, <span class="string">"~/.kube/config"</span>, <span class="string">"kubeconfig file"</span>)</span><br><span class="line">flag.Parse()</span><br><span class="line">config, err := clientcmd.BuildConfigFromFlags(<span class="string">""</span>, *kubeconfig)</span><br><span class="line">clientset, err := client.NewForConfig(config)</span><br><span class="line"></span><br><span class="line">ats := clientset.CnatV1alpha1Interface().Ats(<span class="string">"default"</span>)</span><br><span class="line">book, err := ats.Get(<span class="string">"kubernetes-programming"</span>, metav1.GetOptions&#123;&#125;)</span><br></pre></td></tr></table></figure>
<h3 id="Operator-SDK-and-Kubebuilder的controller-runtime-Client"><a href="#Operator-SDK-and-Kubebuilder的controller-runtime-Client" class="headerlink" title="Operator SDK and Kubebuilder的controller-runtime Client"></a>Operator SDK and Kubebuilder的controller-runtime Client</h3><p>下面是个例子</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> (</span><br><span class="line">    <span class="string">"flag"</span></span><br><span class="line"></span><br><span class="line">    corev1 <span class="string">"k8s.io/api/core/v1"</span></span><br><span class="line">    metav1 <span class="string">"k8s.io/apimachinery/pkg/apis/meta/v1"</span></span><br><span class="line">    <span class="string">"k8s.io/client-go/kubernetes/scheme"</span></span><br><span class="line">    <span class="string">"k8s.io/client-go/tools/clientcmd"</span></span><br><span class="line"></span><br><span class="line">    runtimeclient <span class="string">"sigs.k8s.io/controller-runtime/pkg/client"</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line">kubeconfig = flag.String(<span class="string">"kubeconfig"</span>, <span class="string">"~/.kube/config"</span>, <span class="string">"kubeconfig file path"</span>)</span><br><span class="line">flag.Parse()</span><br><span class="line">config, err := clientcmd.BuildConfigFromFlags(<span class="string">""</span>, *kubeconfig)</span><br><span class="line"></span><br><span class="line">cl, _ := runtimeclient.New(config, client.Options&#123;</span><br><span class="line">    Scheme: scheme.Scheme,</span><br><span class="line">&#125;)</span><br><span class="line">podList := &amp;corev1.PodList&#123;&#125;</span><br><span class="line">err := cl.List(context.TODO(), client.InNamespace(<span class="string">"default"</span>), podList)</span><br></pre></td></tr></table></figure>
<p>在上述中 client object的List()方法接受任何一个给定scheme中的runtime.Object  , 将<em>corev1.PodList这个go类型映射到GVK , 之后由GVR获取pod , 即通过 </em>api/v1/namespace/default/pods*来获取schema.GroupVersionResource{“”, “v1”, “pods”}</p>

    </article>
    <!-- license  -->
    
        <div class="license-wrapper">
            <p>原文作者：<a href="haojianxun.github.io">HAOJX</a>
            <p>原文链接：<a href="haojianxun.github.io/2019/09/08/kuberntes开发教程系列(3)了解和编写Custom Resources/">haojianxun.github.io/2019/09/08/kuberntes开发教程系列(3)了解和编写Custom Resources/</a>
            <p>发表日期：<a href="haojianxun.github.io/2019/09/08/kuberntes开发教程系列(3)了解和编写Custom Resources/">September 8th 2019, 12:00:00 am</a>
            <p>更新日期：<a href="haojianxun.github.io/2019/09/08/kuberntes开发教程系列(3)了解和编写Custom Resources/">September 22nd 2019, 6:32:48 pm</a>
            <p>版权声明：本文采用<a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/">知识共享署名-非商业性使用 4.0 国际许可协议</a>进行许可</p>
        </div>
    
    <!-- paginator  -->
    <ul class="post-paginator">
        <li class="next">
            
                <div class="nextSlogan">Next Post</div>
                <a href= "/2019/09/10/kubernetes开发教程(4)自动代码生成/" title= "kubernetes开发教程(4)--自动代码生成">
                    <div class="nextTitle">kubernetes开发教程(4)--自动代码生成</div>
                </a>
            
        </li>
        <li class="previous">
            
                <div class="prevSlogan">Previous Post</div>
                <a href= "/2019/09/07/kuberntes开发教程系列(2)  了解client-go是什么/" title= "kuberntes开发教程系列(2):了解client-go是什么">
                    <div class="prevTitle">kuberntes开发教程系列(2):了解client-go是什么</div>
                </a>
            
        </li>
    </ul>
    <!-- 评论插件 -->
    <!-- 来必力City版安装代码 -->

<!-- City版安装代码已完成 -->
    
    
    <!-- partial('_partial/comment/changyan') -->
    <!--PC版-->


    
    
    <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
    <script src='//unpkg.com/valine/dist/Valine.min.js'></script>
    <div id="comment"></div>
    <script>
    new Valine({
        el: '#comment' ,
        notify:false, 
        verify:false, 
        appId: "qX8HVjkGrEtM7e6o1RGfcE5K-gzGzoHsz",
        appKey: "q6vTiIUxgUePH7KN2r1bSk6W",
        placeholder: "ヾﾉ≧∀≦)o来啊，快活啊!  如果有技术问题 , 可以在评论中留下您的昵称和邮箱 , 以便于回复",
        path:window.location.pathname, 
        avatar:'mm' 
    });
    </script>


    <!-- 评论 -->
</main>
            <!-- profile -->
            
        </div>
        <footer class="footer footer-unloaded">
    <!-- social  -->
    
    <div class="social">
        
    
        
            
                <a href="mailto:1090468413@qq.com" class="iconfont-archer email" title=email ></a>
            
        
    
        
            
                <a href="//profile-summary-for-github.com/user/haojianxun" class="iconfont-archer github" target="_blank" title=github></a>
            
        
    
        
            
                <span class="iconfont-archer wechat" title=wechat>
                  
                  <img class="profile-qr" src="/assets/example_qr.png" />
                </span>
            
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    

    </div>
    
    <!-- powered by Hexo  -->
    <div class="copyright">
        <span id="hexo-power">Powered by <a href="https://hexo.io/" target="_blank">Hexo</a></span><span class="iconfont-archer power">&#xe635;</span><span id="theme-info">theme <a href="https://github.com/fi3ework/hexo-theme-archer" target="_blank">Archer</a></span>
    </div>
    <!-- 不蒜子  -->
    
    <div class="busuanzi-container">
    
     
    <span id="busuanzi_container_site_pv">PV: <span id="busuanzi_value_site_pv"></span> :)</span>
    
    </div>
    
</footer>
    </div>
    <!-- toc -->
    
    <div class="toc-wrapper" style=
    







top:50vh;

    >
        <div class="toc-catalog">
            <span class="iconfont-archer catalog-icon">&#xe613;</span><span>CATALOG</span>
        </div>
        <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#Discovery-Information"><span class="toc-number">1.</span> <span class="toc-text">Discovery Information</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#自定义资源的编写"><span class="toc-number">2.</span> <span class="toc-text">自定义资源的编写</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Short-Names-and-Categories"><span class="toc-number">2.1.</span> <span class="toc-text">Short Names and Categories</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Printer-Columns"><span class="toc-number">2.2.</span> <span class="toc-text">Printer Columns</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#子资源状态"><span class="toc-number">3.</span> <span class="toc-text">子资源状态</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#status状态子资源启用"><span class="toc-number">3.1.</span> <span class="toc-text">status状态子资源启用</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#scale子资源"><span class="toc-number">3.2.</span> <span class="toc-text">scale子资源</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#使用golang访问Custom-resources"><span class="toc-number">4.</span> <span class="toc-text">使用golang访问Custom resources</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Dynamic-Client"><span class="toc-number">4.1.</span> <span class="toc-text">Dynamic Client</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Typed-Clients"><span class="toc-number">4.2.</span> <span class="toc-text">Typed Clients</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#golang包的组织"><span class="toc-number">5.</span> <span class="toc-text">golang包的组织</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#通过client-gen生成typed-client"><span class="toc-number">5.1.</span> <span class="toc-text">通过client-gen生成typed client</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Operator-SDK-and-Kubebuilder的controller-runtime-Client"><span class="toc-number">5.2.</span> <span class="toc-text">Operator SDK and Kubebuilder的controller-runtime Client</span></a></li></ol></li></ol>
    </div>
    
    <div class="back-top iconfont-archer">&#xe639;</div>
    <div class="sidebar sidebar-hide">
    <ul class="sidebar-tabs sidebar-tabs-active-0">
        <li class="sidebar-tab-archives"><span class="iconfont-archer">&#xe67d;</span><span class="tab-name">Archive</span></li>
        <li class="sidebar-tab-tags"><span class="iconfont-archer">&#xe61b;</span><span class="tab-name">Tag</span></li>
        <li class="sidebar-tab-categories"><span class="iconfont-archer">&#xe666;</span><span class="tab-name">Cate</span></li>
    </ul>
    <div class="sidebar-content sidebar-content-show-archive">
          <div class="sidebar-panel-archives">
    <!-- 在ejs中将archive按照时间排序 -->
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    <div class="total-and-search">
        <div class="total-archive">
        Total : 168
        </div>
        <!-- search  -->
        
    </div>
    
    <div class="post-archive">
    
    
    
    
    <div class="archive-year"> 2022 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">01/08</span><a class="archive-post-title" href= "/2022/01/08/K8s-leaderElection选主的写法套路/" >K8s leaderElection选主的写法套路</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> 2021 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">12/30</span><a class="archive-post-title" href= "/2021/12/30/k8s中如何远程执行pod命令/" >k8s中如何远程执行pod命令</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">12/01</span><a class="archive-post-title" href= "/2021/12/01/clientset中patch操作-策略性补丁之替换/" >clientset中patch操作-策略性补丁之替换</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">12/01</span><a class="archive-post-title" href= "/2021/12/01/fake-client的用法/" >fake-client的用法</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/25</span><a class="archive-post-title" href= "/2021/11/25/CRD开发中监控deployment的变化,并且显示在控制台/" >CRD开发中监控deployment的变化,并且显示在控制台</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/25</span><a class="archive-post-title" href= "/2021/11/25/k8s-reconcile中client如何使用patch/" >k8s reconcile中client如何使用patch</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/24</span><a class="archive-post-title" href= "/2021/11/24/k8s中如何发送http请求给api-server/" >k8s中如何发送http请求给api-server</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/17</span><a class="archive-post-title" href= "/2021/11/17/clientset中patch操作jsonpatch/" >clientset中patch操作:jsonpatch</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/29</span><a class="archive-post-title" href= "/2021/10/29/event的用法,-来显示资源的事件情况/" >event的用法, 来显示资源的事件情况</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/09</span><a class="archive-post-title" href= "/2021/10/09/dynamic-Client的使用方法/" >dynamic-Client的使用方法</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> 2020 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/15</span><a class="archive-post-title" href= "/2020/10/15/Operator介绍(1)/" >Operator介绍(1)</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/15</span><a class="archive-post-title" href= "/2020/10/15/Operator介绍(2)---以etcd-operator为例/" >Operator介绍(2)---以etcd-operator为例</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/15</span><a class="archive-post-title" href= "/2020/10/15/Operator SDK开发简介/" >Operator SDK开发简介</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">01/05</span><a class="archive-post-title" href= "/2020/01/05/kubernetes-的负载均衡策略/" >kubernetes 的负载均衡策略</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> 2019 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">03/01</span><a class="archive-post-title" href= "/2019/03/01/kubernetes DaemonSet是如何进行版本管理的/" >kubernetes DaemonSet是如何进行版本管理的</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">03/01</span><a class="archive-post-title" href= "/2019/03/01/kubernetes DaemonSet是如何保证pod只在一个节点上运行并且保证数量是1/" >kubernetes DaemonSet是如何保证pod只在一个节点上运行并且保证数量是1</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">03/01</span><a class="archive-post-title" href= "/2019/03/01/kubernetes deployment在滚动升级的时候如何控制新旧pod比例/" >kubernetes deployment在滚动升级的时候如何控制新旧pod比例</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">03/01</span><a class="archive-post-title" href= "/2019/03/01/kubernetes deployment如何控制每次更新操作只触发一个ReolicaSet以及设置保留历史个数版本/" >kubernetes deployment如何控制每次更新操作只触发一个ReolicaSet以及设置保留历史个数版本</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">03/01</span><a class="archive-post-title" href= "/2019/03/01/kubernetes中如何让pod指定声明使用某个特定的initializer/" >kubernetes中如何让pod指定声明使用某个特定的initializer</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">01/02</span><a class="archive-post-title" href= "/2019/01/02/CNCF云原生生态系统大览(CNCF-Cloud-Native-Interactive-Landscape)/" >构建企业级云服务生态指南---CNCF云原生生态系统大览</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">01/02</span><a class="archive-post-title" href= "/2019/01/02/StorageClass--kubernetes自动创建pv的机制(Dynamic-Provisioning)/" >StorageClass---kubernetes自动创建pv的机制(Dynamic Provisioning)</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> 2018 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">12/22</span><a class="archive-post-title" href= "/2018/12/22/kubernetes-EFK实践/" >kubernetes EFK实践</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">12/05</span><a class="archive-post-title" href= "/2018/12/05/kubelet是如何操作容器管理pod的/" >kubelet是如何操作容器管理pod的</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/10</span><a class="archive-post-title" href= "/2018/11/10/kubernetes CRD下篇--编写自定义控制器/" >kubernetes CRD下篇--编写自定义控制器</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/05</span><a class="archive-post-title" href= "/2018/11/05/kuberadm初始化的时候使用自定义镜像源方法/" >kuberadm初始化的时候使用自定义镜像源方法</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/03</span><a class="archive-post-title" href= "/2018/11/03/kubernetes中的Projected Volume是什么/" >kubernetes中的Projected Volume是什么</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/01</span><a class="archive-post-title" href= "/2018/11/01/kubernetes中的控制器模型-以Deployment的实现为例/" >kubernetes中的"控制器"模型-以Deployment的实现为例</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/14</span><a class="archive-post-title" href= "/2018/10/14/ginx中HTTP请求的11个阶段之第九阶段--precontent阶段/" >Nginx中HTTP请求的11个阶段之第九阶段--precontent阶段</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">06/27</span><a class="archive-post-title" href= "/2018/06/27/kubeadm的配置文件路径和意义/" >kubeadm的配置文件路径和意义</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">05/11</span><a class="archive-post-title" href= "/2018/05/11/heapster部署/" >heapster部署</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">03/27</span><a class="archive-post-title" href= "/2018/03/27/kubeadm init可能出现的问题/" >kubeadm init可能出现的问题</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> 2016 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">04/25</span><a class="archive-post-title" href= "/2016/04/25/hello-world/" >Hello World</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes  RBAC认证和serviceaccount/" >kubernetes认证和serviceaccount</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes ConfigMap/" >kubernetes ConfigMap</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes HPA/" >kubernetes HPA</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes StatefulSet/" >kubernetes StatefulSet</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes RBAC/" >kubernetes RBAC</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes dashboard部署/" >kubernetes dashboard部署</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes service实现方法和类型/" >kubernetes service实现方法和类型</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes ingress controller的配置和工作过程/" >kubernetes ingress controller的配置和工作过程</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> 2018 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/03</span><a class="archive-post-title" href= "/2018/11/03/kubernetes中api-server的地址改成公网ip和负载均衡/" >kubernetes中api-server的地址改成公网ip和负载均衡</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/02</span><a class="archive-post-title" href= "/2018/11/02/Kubernetes 存储插件项目：Rook/" >Kubernetes 存储插件项目：Rook</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/30</span><a class="archive-post-title" href= "/2018/10/30/Deployment 对应用进行版本控制的具体原理--以金丝雀发布（Canary Deployment）为例/" >Deployment 对应用进行版本控制的具体原理--以金丝雀发布（Canary Deployment）为例</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/15</span><a class="archive-post-title" href= "/2018/10/15/Nginx中HTTP请求的11个阶段之第七阶段--access阶段做权限控制,ip限制/" >Nginx中HTTP请求的11个阶段之第七阶段--access阶段做权限控制,ip限制</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/14</span><a class="archive-post-title" href= "/2018/10/14/Nginx中HTTP请求的11个阶段之第十阶段---content阶段(root和alias指令)/" >Nginx中HTTP请求的11个阶段之第十阶段---content阶段(root和alias指令)</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/13</span><a class="archive-post-title" href= "/2018/10/13/Nginx中HTTP请求的11个阶段之第十一个阶段---log阶段/" >Nginx中HTTP请求的11个阶段之第十一个阶段---log阶段</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/12</span><a class="archive-post-title" href= "/2018/10/12/Nginx中HTTP框架提供的变量/" >Nginx中HTTP框架提供的变量</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/10</span><a class="archive-post-title" href= "/2018/10/10/Nginx中HTTP请求的11个阶段之第一阶段----postread阶段/" >Nginx中HTTP请求的11个阶段之第一阶段----postread阶段(realip模块)</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/10</span><a class="archive-post-title" href= "/2018/10/10/Nginx中HTTP请求的11个阶段之第三阶段----find_config  (location指令)/" >Nginx中HTTP请求的11个阶段之第三阶段----find_config  (location指令)</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/10</span><a class="archive-post-title" href= "/2018/10/10/Nginx中HTTP请求的11个阶段之第二阶段和第四阶段---rewrite阶段/" >Nginx中HTTP请求的11个阶段之第二阶段和第四阶段---rewrite阶段</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/10</span><a class="archive-post-title" href= "/2018/10/10/Nginx中HTTP请求的11个阶段之第六阶段---PREACCESS (limit_req ,limit_conn模块)/" >Nginx中HTTP请求的11个阶段之第六阶段---PREACCESS (limit_req ,limit_conn模块)</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes中docker连到私有仓库认证问题/" >kubernetes中docker连到私有仓库认证问题</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> 2018 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">08/06</span><a class="archive-post-title" href= "/2018/08/06/kubernetes中的volumes挂载类型为emptydir,在宿主机上的路径在哪/" >kubernetes中的volumes挂载类型为emptydir,在宿主机上的路径在哪</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">08/01</span><a class="archive-post-title" href= "/2018/08/01/docker是如何创建容器的pid为1的进程的/" >docker是如何创建容器的pid为1的进程的</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">07/22</span><a class="archive-post-title" href= "/2018/07/22/kubernetes中kubeconfig是什么/" >kubernetes中kubeconfig是什么?</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">07/06</span><a class="archive-post-title" href= "/2018/07/06/docker是如何做到资源限制的/" >docker是如何做到资源限制的</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">06/22</span><a class="archive-post-title" href= "/2018/06/22/Helm/" >Helm</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">03/24</span><a class="archive-post-title" href= "/2018/03/24/docker exec 是怎么做到进入容器里的呢？/" >docker exec 是怎么做到进入容器里的呢？</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">03/11</span><a class="archive-post-title" href= "/2018/03/11/docker如何修复容器中的 top 指令以及 proc 文件系统中的信息呢/" >docker如何修复容器中的 top 指令以及 /proc 文件系统中的信息呢</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> 2017 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">07/07</span><a class="archive-post-title" href= "/2017/07/07/docker私有仓库--docker-distribution/" >docker私有仓库--docker-distribution</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">06/22</span><a class="archive-post-title" href= "/2017/06/22/Docker 容器明文密码解决的2个方法/" >Docker 容器明文密码解决的2个方法</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">06/11</span><a class="archive-post-title" href= "/2017/06/11/docker自定义docker0网桥网络属性/" >docker自定义docker0网桥网络属性</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">06/07</span><a class="archive-post-title" href= "/2017/06/07/dockerfile常用指令/" >dockerfile常用指令</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">06/07</span><a class="archive-post-title" href= "/2017/06/07/docker网络初探/" >docker网络初探</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">05/11</span><a class="archive-post-title" href= "/2017/05/11/docker网络/" >docker网络</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">05/09</span><a class="archive-post-title" href= "/2017/05/09/docker列出镜像用法/" >docker列出镜像用法</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">04/23</span><a class="archive-post-title" href= "/2017/04/23/docker相关命令--pull , commit ,save,load/" >docker相关命令--pull , commit ,save,load</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">04/07</span><a class="archive-post-title" href= "/2017/04/07/docker私有仓库--Harbor/" >docker私有仓库--Harbor</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">03/17</span><a class="archive-post-title" href= "/2017/03/17/docker相关机构/" >docker相关机构</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">03/11</span><a class="archive-post-title" href= "/2017/03/11/docker端口映射/" >docker端口映射</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">02/15</span><a class="archive-post-title" href= "/2017/02/15/docker存储卷/" >docker存储卷</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">02/11</span><a class="archive-post-title" href= "/2017/02/11/Docker Daemon 的作用是什么/" >Docker Daemon 的作用是什么</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">02/11</span><a class="archive-post-title" href= "/2017/02/11/docker image分层构建 联合挂载/" >docker</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">01/24</span><a class="archive-post-title" href= "/2017/01/24/docker安装/" >docker安装</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">01/21</span><a class="archive-post-title" href= "/2017/01/21/docker相关概念/" >docker相关概念</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">01/04</span><a class="archive-post-title" href= "/2017/01/04/docker官方设置http_proxy教程/" >docker官方设置http_proxy教程</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> 2016 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">05/19</span><a class="archive-post-title" href= "/2016/05/19/docker镜像加速的方法/" >docker镜像加速的方法</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes中查看pod内部的dns解析/" >kubernetes中查看pod内部的dns解析</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes中的认证---default-token/" >kubernetes中的认证---default-token</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes中的认证流程和资源请求/" >kubernetes中的认证流程和资源请求</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes中的账号/" >kubernetes中的账号</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes中资源yaml模板创建/" >kubernetes中资源yaml模板创建</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes中网络插件地址/" >kubernetes中网络插件地址</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes中进入pod运行命令/" >kubernetes进入pod方法</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes中部署prometheus/" >kubernetes中部署prometheus</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes中资源的引用方式/" >kubernetes中资源的引用方式</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes中部署一个服务用的简单模板/" >kubernetes中部署一个服务用的简单模板</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> 2021 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">12/28</span><a class="archive-post-title" href= "/2021/12/28/mgr.Add函数用法在mgr启动的时候会一起把这个对象也启动了/" >mgr.Add函数用法:在mgr启动的时候会一起把这个对象也启动了</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">12/27</span><a class="archive-post-title" href= "/2021/12/27/mgr中开启控制器选主/" >mgr中开启控制器选主</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> 2019 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">09/10</span><a class="archive-post-title" href= "/2019/09/10/kubernetes开发教程(4)自动代码生成/" >kubernetes开发教程(4)--自动代码生成</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">09/08</span><a class="archive-post-title" href= "/2019/09/08/kuberntes开发教程系列(3)了解和编写Custom Resources/" >kuberntes开发教程系列(3)--了解和编写Custom Resources</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">09/07</span><a class="archive-post-title" href= "/2019/09/07/kuberntes开发教程系列(2)  了解client-go是什么/" >kuberntes开发教程系列(2):了解client-go是什么</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">09/06</span><a class="archive-post-title" href= "/2019/09/06/kuberntes开发教程系列(一)认识kuberntes API/" >kuberntes开发教程系列(1):认识kuberntes API</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">06/24</span><a class="archive-post-title" href= "/2019/06/24/kubernetes持久化存储卷存储卷快照Snapshot/" >kubernetes持久化存储卷:存储卷快照Snapshot详解</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">01/10</span><a class="archive-post-title" href= "/2019/01/10/kubernetes的本地持久化存储--Local Persistent Volume解析/" >kubernetes的本地持久化存储--Local Persistent Volume解析</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">01/02</span><a class="archive-post-title" href= "/2019/01/02/kubernetes挂载卷的基本过程/" >kubernetes挂载卷的基本过程</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> 2018 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">12/21</span><a class="archive-post-title" href= "/2018/12/21/kubernetes容器日志收集方案/" >kubernetes容器日志收集方案</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/27</span><a class="archive-post-title" href= "/2018/11/27/kubernetes怎么修改与设置触发资源回收策略的默认值/" >kubernetes怎么修改与设置触发资源回收策略的默认值</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/26</span><a class="archive-post-title" href= "/2018/11/26/kubernetes中默认调度器是如何调度一个pod的到节点上的/" >kubernetes中默认调度器的调度流程是怎么进行的</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/16</span><a class="archive-post-title" href= "/2018/11/16/kubernetes中默认为pod创建的volume目录是在宿主机的什么路径/" >kubernetes中默认为pod创建的volume目录是在宿主机的什么路径</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/10</span><a class="archive-post-title" href= "/2018/11/10/kubernetes动态准入控制Initializers是什么/" >kubernetes动态准入控制Initializers是什么</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/10</span><a class="archive-post-title" href= "/2018/11/10/kubernetes是如何创建api对象的/" >kubernetes是如何创建api对象的</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/15</span><a class="archive-post-title" href= "/2018/10/15/nginx中upstream模块提供的变量(不含cache)/" >nginx中upstream模块提供的变量(不含cache)</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/15</span><a class="archive-post-title" href= "/2018/10/15/nginx中缓存用法和优化/" >nginx中缓存用法和优化</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/05</span><a class="archive-post-title" href= "/2018/10/05/nginx架构基础相关知识/" >nginx架构基础相关知识</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">01/05</span><a class="archive-post-title" href= "/2018/01/05/kubernetes初探/" >kubernetes初探</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes如何创建被认证的用户/" >kubernetes如何创建被认证的用户</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes存储卷/" >kubernetes存储卷</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes访问集群节点的资源/" >kubernetes访问集群节点的资源</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes组件/" >kubernetes组件</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> 2018 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">09/28</span><a class="archive-post-title" href= "/2018/09/28/kubernetes调度pod策略/" >kubernetes调度pod策略</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes资源定义清单中的apiVersion说明/" >kubernetes资源定义清单中的apiVersion说明</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes资源指标metrics-server/" >kubernetes资源指标metrics-server</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes资源清单/" >kubernetes资源清单</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> 2018 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/06</span><a class="archive-post-title" href= "/2018/11/06/kubernetes部署dashboard(nginx-ingress模式访问)/" >kubernetes部署dashboard(nginx-ingress模式访问)</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/20</span><a class="archive-post-title" href= "/2018/10/20/kubernetes部署metrics-server(2)/" >kubernetes部署metrics-server(2)</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes集群的外部地址和内部地址/" >kubernetes集群的外部地址和内部地址</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes高级调度方式/" >kubernetes高级调度方式</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> 2018 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/15</span><a class="archive-post-title" href= "/2018/10/15/nginx中的keepalive , 共享内存/" >nginx中的keepalive , 共享内存</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/15</span><a class="archive-post-title" href= "/2018/10/15/nginx使用open_file_cache提升系统性能/" >nginx使用open_file_cache提升系统性能</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/10</span><a class="archive-post-title" href= "/2018/10/10/nginx中的http反向代理流程及proxy模块/" >nginx中的http反向代理流程及proxy模块</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> 2016 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">03/11</span><a class="archive-post-title" href= "/2016/03/11/linux的五种IO模型/" >linux的五种IO模型</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/kubernetes资源限制/" >kubernetes资源限制</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> Invalid date </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">Invalid date</span><a class="archive-post-title" href= "/2019/09/02/nginx-ingress/" >一个nginx-ingress部署示例</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> 2022 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">03/22</span><a class="archive-post-title" href= "/2022/03/22/取任意yaml资源转化为k8s资源的完全通用写法(kubectl源码的写法)/" >取任意yaml资源转化为k8s资源的完全通用写法(kubectl源码的写法)</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">01/05</span><a class="archive-post-title" href= "/2022/01/05/如何解析caCert,caPrikey/" >如何解析caCert,caPrikey</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">01/05</span><a class="archive-post-title" href= "/2022/01/05/代码自动签发证书/" >代码自动签发证书</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">01/03</span><a class="archive-post-title" href= "/2022/01/03/写个通用代码来模拟kubectl-apply文件/" >写个通用代码来模拟kubectl apply文件(kustomize模式)</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">01/01</span><a class="archive-post-title" href= "/2022/01/01/如何代码创建自定义用户的config文件/" >如何代码创建自定义用户的config文件</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> 2021 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">12/29</span><a class="archive-post-title" href= "/2021/12/29/如何通过grk来找gvr,或者gvr找gvk/" >如何通过grk来找gvr,或者gvr找gvk</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/26</span><a class="archive-post-title" href= "/2021/11/26/代码获取pod的日志/" >代码获取pod的日志</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/25</span><a class="archive-post-title" href= "/2021/11/25/获取资源api-reasources/" >获取资源api-reasources</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/15</span><a class="archive-post-title" href= "/2021/11/15/自定义controller如何重新拉起被删除的资源/" >自定义controller如何重新拉起被删除的资源</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/13</span><a class="archive-post-title" href= "/2021/11/13/判断某个rs是否从属于某个deployment/" >判断某个rs是否从属于某个deployment</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/05</span><a class="archive-post-title" href= "/2021/11/05/命令行中如何取到serviceaccout的token/" >命令行中如何取到serviceaccout的token</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/05</span><a class="archive-post-title" href= "/2021/11/05/如何配置token来访问api-server/" >如何配置token来访问api-server</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/25</span><a class="archive-post-title" href= "/2021/10/25/通过labelSelector来选择pod操作/" >通过labelSelector来选择pod操作</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/17</span><a class="archive-post-title" href= "/2021/10/17/初始化控制器controller-runtime中mgr的例子/" >初始化控制器controller-runtime中mgr的例子</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">09/29</span><a class="archive-post-title" href= "/2021/09/29/生成config和client的几种写法/" >生成config和client的几种写法</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">09/17</span><a class="archive-post-title" href= "/2021/09/17/强制删除ns/" >强制删除ns</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">09/10</span><a class="archive-post-title" href= "/2021/09/10/reconcile的时候如何判断一个资源是否已经存在/" >reconcile的时候如何判断一个资源是否已经存在</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">07/05</span><a class="archive-post-title" href= "/2021/07/05/创建config和clientset/" >创建config和clientset</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> 2020 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/22</span><a class="archive-post-title" href= "/2020/10/22/创建k8s用户账号/" >创建k8s用户账号</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">09/29</span><a class="archive-post-title" href= "/2020/09/29/如何级联删除资源/" >如何级联删除资源</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">05/17</span><a class="archive-post-title" href= "/2020/05/17/使用临时调试容器来进行调试/" >使用临时调试容器来进行调试</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> 2019 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/17</span><a class="archive-post-title" href= "/2019/10/17/如何取出kubectl结果里面的pod名称/" >如何取出kubectl结果里面的pod名称</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> 2018 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">12/03</span><a class="archive-post-title" href= "/2018/12/03/yaml转json/" >yaml转json</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">12/03</span><a class="archive-post-title" href= "/2018/12/03/在kubernetes中如何增加和使用node节点上的自定义资源数量/" >在kubernetes中如何增加和使用node节点上的自定义资源数量</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/25</span><a class="archive-post-title" href= "/2018/11/25/在kubernetes中如何让pod绑定在某颗cpu上/" >在kubernetes中如何让pod绑定在某颗cpu上</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/25</span><a class="archive-post-title" href= "/2018/11/25/当在kubernetes中触发了资源回收策略的时候, pod删除的序列是什么/" >当在kubernetes中触发了资源回收策略的时候, pod删除的序列是什么</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/15</span><a class="archive-post-title" href= "/2018/11/15/基于canel的网络策略/" >基于canel的网络策略</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/10</span><a class="archive-post-title" href= "/2018/11/10/在kubernetes中如何添加CRD(Custom Resource Definition)/" >在kubernetes中如何添加CRD(Custom Resource Definition)(1)</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/07</span><a class="archive-post-title" href= "/2018/11/07/prometheus报警--------通过slack发送报警内容/" >prometheus报警--------通过slack发送报警内容</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/02</span><a class="archive-post-title" href= "/2018/11/02/在kubernetes中如何给pod自动填充某些字段/" >在kubernetes中如何给pod自动填充某些默认字段</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/15</span><a class="archive-post-title" href= "/2018/10/15/nginx中的负载均衡算法/" >nginx中的负载均衡算法</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">10/12</span><a class="archive-post-title" href= "/2018/10/12/利用TravisCI同步gcr.io镜像到dockerhub/" >利用TravisCI同步gcr.io镜像到dockerhub</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">09/25</span><a class="archive-post-title" href= "/2018/09/25/部署一个有证书的ingress-nginx/" >部署一个有证书的ingress-nginx</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">08/08</span><a class="archive-post-title" href= "/2018/08/08/prometheus安装/" >prometheus安装</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">05/03</span><a class="archive-post-title" href= "/2018/05/03/理解docker的rootfs和分层构建联合挂载的概念/" >理解docker的rootfs和分层构建联合挂载的概念</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">03/29</span><a class="archive-post-title" href= "/2018/03/29/容器内配置文件和环境变量,参数的传递/" >容器内配置文件和环境变量,参数的传递</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">03/11</span><a class="archive-post-title" href= "/2018/03/11/解决kubeadm安装k8s的时候images不能下载的问题--方法2/" >解决kubeadm安装k8s的时候images不能下载的问题--方法2</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">02/13</span><a class="archive-post-title" href= "/2018/02/13/为什么kubernetes集群上master不会被调度/" >为什么kubernetes集群上master不会被调度</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">02/12</span><a class="archive-post-title" href= "/2018/02/12/使用kubeadm从0开始搭建kubernetesv1.11.1/" >使用kubeadm从0开始搭建kubernetes:v1.11.1</a>
        </li>
    
    
    
    
    
        </ul>
    
    <div class="archive-year"> 2017 </div>
    <ul class="year-list">
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">11/07</span><a class="archive-post-title" href= "/2017/11/07/tcpdump nc nmap/" >tcpdump nc nmap</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">09/22</span><a class="archive-post-title" href= "/2017/09/22/使用ssh进行git登陆和推送/" >使用ssh进行git登陆和推送</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">06/07</span><a class="archive-post-title" href= "/2017/06/07/用entrypoint脚本来初始化docker自定义配置文件-以nginx为例/" >用entrypoint脚本来初始化docker自定义配置文件-以nginx为例</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">05/25</span><a class="archive-post-title" href= "/2017/05/25/容器发展史和docker容器核心技术--chroot ,namespace和cgroups/" >容器核心技术--chroot ,namespace,cgroups,LCX,和docker</a>
        </li>
    
    
        <li class="archive-post-item">
            <span class="archive-post-date">02/05</span><a class="archive-post-title" href= "/2017/02/05/国内docker hub的加速镜像服务/" >国内docker hub的加速镜像服务</a>
        </li>
    
    </div>
  </div>
        <div class="sidebar-panel-tags">
    <div class="sidebar-tags-name">
    
        <span class="sidebar-tag-name" data-tags="kubernetes"><span class="iconfont-archer">&#xe606;</span>kubernetes</span>
    
        <span class="sidebar-tag-name" data-tags="docker"><span class="iconfont-archer">&#xe606;</span>docker</span>
    
        <span class="sidebar-tag-name" data-tags="helm"><span class="iconfont-archer">&#xe606;</span>helm</span>
    
        <span class="sidebar-tag-name" data-tags="tips"><span class="iconfont-archer">&#xe606;</span>tips</span>
    
        <span class="sidebar-tag-name" data-tags="harbor"><span class="iconfont-archer">&#xe606;</span>harbor</span>
    
        <span class="sidebar-tag-name" data-tags="docker网络"><span class="iconfont-archer">&#xe606;</span>docker网络</span>
    
        <span class="sidebar-tag-name" data-tags="heapster"><span class="iconfont-archer">&#xe606;</span>heapster</span>
    
        <span class="sidebar-tag-name" data-tags="serviceaccount"><span class="iconfont-archer">&#xe606;</span>serviceaccount</span>
    
        <span class="sidebar-tag-name" data-tags="configmap"><span class="iconfont-archer">&#xe606;</span>configmap</span>
    
        <span class="sidebar-tag-name" data-tags="HPA"><span class="iconfont-archer">&#xe606;</span>HPA</span>
    
        <span class="sidebar-tag-name" data-tags="kbuernetes statefulset"><span class="iconfont-archer">&#xe606;</span>kbuernetes statefulset</span>
    
        <span class="sidebar-tag-name" data-tags="RBAC"><span class="iconfont-archer">&#xe606;</span>RBAC</span>
    
        <span class="sidebar-tag-name" data-tags="kubernetes service"><span class="iconfont-archer">&#xe606;</span>kubernetes service</span>
    
        <span class="sidebar-tag-name" data-tags="ingress"><span class="iconfont-archer">&#xe606;</span>ingress</span>
    
        <span class="sidebar-tag-name" data-tags="prometheus"><span class="iconfont-archer">&#xe606;</span>prometheus</span>
    
        <span class="sidebar-tag-name" data-tags="kubernetes 存储卷"><span class="iconfont-archer">&#xe606;</span>kubernetes 存储卷</span>
    
        <span class="sidebar-tag-name" data-tags="kubernetes资源"><span class="iconfont-archer">&#xe606;</span>kubernetes资源</span>
    
        <span class="sidebar-tag-name" data-tags="kubernetes调度"><span class="iconfont-archer">&#xe606;</span>kubernetes调度</span>
    
        <span class="sidebar-tag-name" data-tags="linux base"><span class="iconfont-archer">&#xe606;</span>linux base</span>
    
        <span class="sidebar-tag-name" data-tags="ingress-nginx"><span class="iconfont-archer">&#xe606;</span>ingress-nginx</span>
    
        <span class="sidebar-tag-name" data-tags="Linux"><span class="iconfont-archer">&#xe606;</span>Linux</span>
    
        <span class="sidebar-tag-name" data-tags="kubernetes安装"><span class="iconfont-archer">&#xe606;</span>kubernetes安装</span>
    
        <span class="sidebar-tag-name" data-tags="git"><span class="iconfont-archer">&#xe606;</span>git</span>
    
        <span class="sidebar-tag-name" data-tags="travis"><span class="iconfont-archer">&#xe606;</span>travis</span>
    
        <span class="sidebar-tag-name" data-tags="gcr.io镜像"><span class="iconfont-archer">&#xe606;</span>gcr.io镜像</span>
    
        <span class="sidebar-tag-name" data-tags="kubernetes网络策略"><span class="iconfont-archer">&#xe606;</span>kubernetes网络策略</span>
    
    </div>
    <div class="iconfont-archer sidebar-tags-empty">&#xe678;</div>
    <div class="tag-load-fail" style="display: none; color: #ccc; font-size: 0.6rem;">
    缺失模块。<br/>
    1、请确保node版本大于6.2<br/>
    2、在博客根目录（注意不是archer根目录）执行以下命令：<br/>
    <span style="color: #f75357; font-size: 1rem; line-height: 2rem;">npm i hexo-generator-json-content --save</span><br/>
    3、在根目录_config.yml里添加配置：
    <pre style="color: #787878; font-size: 0.6rem;">
jsonContent:
  meta: false
  pages: false
  posts:
    title: true
    date: true
    path: true
    text: false
    raw: false
    content: false
    slug: false
    updated: false
    comments: false
    link: false
    permalink: false
    excerpt: false
    categories: true
    tags: true</pre>
    </div> 
    <div class="sidebar-tags-list"></div>
</div>
        <div class="sidebar-panel-categories">
    <div class="sidebar-categories-name">
    
        <span class="sidebar-category-name" data-categories="kubernetes"><span class="iconfont-archer">&#xe60a;</span>kubernetes</span>
    
        <span class="sidebar-category-name" data-categories="tips"><span class="iconfont-archer">&#xe60a;</span>tips</span>
    
        <span class="sidebar-category-name" data-categories="docker"><span class="iconfont-archer">&#xe60a;</span>docker</span>
    
        <span class="sidebar-category-name" data-categories="nginx"><span class="iconfont-archer">&#xe60a;</span>nginx</span>
    
        <span class="sidebar-category-name" data-categories="docker/tips"><span class="iconfont-archer">&#xe60a;</span>docker/tips</span>
    
        <span class="sidebar-category-name" data-categories="kuberntes"><span class="iconfont-archer">&#xe60a;</span>kuberntes</span>
    
        <span class="sidebar-category-name" data-categories="linux"><span class="iconfont-archer">&#xe60a;</span>linux</span>
    
        <span class="sidebar-category-name" data-categories="Linux-Base"><span class="iconfont-archer">&#xe60a;</span>Linux-Base</span>
    
        <span class="sidebar-category-name" data-categories="tips/docker"><span class="iconfont-archer">&#xe60a;</span>tips/docker</span>
    
    </div>
    <div class="iconfont-archer sidebar-categories-empty">&#xe678;</div>
    <div class="sidebar-categories-list"></div>
</div>
    </div>
</div> 
    <script>
    var siteMeta = {
        root: "/",
        author: "HAOJX"
    }
</script>
    <!-- CDN failover -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js"></script>
    <script type="text/javascript">
        if (typeof window.$ === 'undefined')
        {
            console.warn('jquery load from jsdelivr failed, will load local script')
            document.write('<script src="/lib/jquery.min.js">\x3C/script>')
        }
    </script>
    <script src="/scripts/main.js"></script>
    <!-- algolia -->
    
    <!-- busuanzi  -->
    
    <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    
    <!-- CNZZ  -->
    
    </div>
    <!-- async load share.js -->
    
        <script src="/scripts/share.js" async></script>    
     
    <script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"live2d-widget-model-tororo"},"display":{"position":"left","width":150,"height":300},"mobile":{"show":true},"log":false});</script></body>
</html>


